/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.uml.BehaviorStateMachines;
// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.*;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.model.xml.XMLUtility;

import edu.pku.sei.modeler.model.uml.Kernel.Constraint;
import edu.pku.sei.modeler.model.uml.Communications.Trigger;
import edu.pku.sei.modeler.model.uml.BasicBehaviors.Behavior;
import edu.pku.sei.modeler.model.uml.BasicBehaviors.Behavior;
import edu.pku.sei.modeler.model.uml.BasicBehaviors.Behavior;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;
import edu.pku.sei.modeler.model.uml.Kernel.RedefinableElement;

import edu.pku.sei.modeler.model.uml.Kernel.Namespace;
import edu.pku.sei.modeler.uml.modelHelper.ModelPackage;

/**
 * @generated
 *
 */
public class State extends Namespace implements IState {
	// attributes
	
	protected boolean isComposite;
	
	protected boolean isOrthogonal;
	
	protected boolean isSimple;
	
	protected boolean isSubmachineState;
	
	
	
	protected boolean isLeaf;
	
	
	// references
	
	protected MetaTypedList stateInvariant;
	
	protected MetaTypedList deferrableTrigger;
	
	protected MetaTypedList entry;
	
	protected MetaTypedList exit;
	
	protected MetaTypedList doActvity;
	
	protected MetaTypedList connection;
	
	protected MetaTypedList connectionPoint;
	
	protected MetaTypedList region;
	
	protected MetaTypedList submachine;
	
	protected MetaTypedList redefinedState;
	
	
	
	protected MetaTypedList outgoing;
	
	protected MetaTypedList incoming;
	
	protected MetaTypedList redefinitionContext;
	
	protected MetaTypedList redefinedElement;
	
	
	public State(){
		this.name = "unnamed state";
	}
	
	// getters & setters for attributes
	
	@MethodProperty(
			id = "STATE_ISCOMPOSITE",
			catalog = "Model",
			name = ModelPackage.STATE_ISCOMPOSITE,
			setter = "setisComposite"
			)
	
	public boolean getIsComposite() {
		return isComposite;
	}
	public void setIsComposite(boolean newIsComposite) {
		boolean oldisComposite = isComposite;
		isComposite = newIsComposite;
		firePropertyChange(ModelPackage.STATE_ISCOMPOSITE, oldisComposite, newIsComposite);
	}
	
	@MethodProperty(
			id = "STATE_ISORTHOGONAL",
			catalog = "Model",
			name = ModelPackage.STATE_ISORTHOGONAL,
			setter = "setisOrthogonal"
			)
	
	public boolean getIsOrthogonal() {
		return isOrthogonal;
	}
	public void setIsOrthogonal(boolean newIsOrthogonal) {
		boolean oldisOrthogonal = isOrthogonal;
		isOrthogonal = newIsOrthogonal;
		firePropertyChange(ModelPackage.STATE_ISORTHOGONAL, oldisOrthogonal, newIsOrthogonal);
	}
	
	@MethodProperty(
			id = "STATE_ISSIMPLE",
			catalog = "Model",
			name = ModelPackage.STATE_ISSIMPLE,
			setter = "setisSimple"
			)
	
	public boolean getIsSimple() {
		return isSimple;
	}
	public void setIsSimple(boolean newIsSimple) {
		boolean oldisSimple = isSimple;
		isSimple = newIsSimple;
		firePropertyChange(ModelPackage.STATE_ISSIMPLE, oldisSimple, newIsSimple);
	}
	
	@MethodProperty(
			id = "STATE_ISSUBMACHINESTATE",
			catalog = "Model",
			name = ModelPackage.STATE_ISSUBMACHINESTATE,
			setter = "setisSubmachineState"
			)
	
	public boolean getIsSubmachineState() {
		return isSubmachineState;
	}
	public void setIsSubmachineState(boolean newIsSubmachineState) {
		boolean oldisSubmachineState = isSubmachineState;
		isSubmachineState = newIsSubmachineState;
		firePropertyChange(ModelPackage.STATE_ISSUBMACHINESTATE, oldisSubmachineState, newIsSubmachineState);
	}
	
	@MethodProperty(
			id = "STATE_ISLEAF",
			catalog = "Model",
			name = ModelPackage.REDEFINABLEELEMENT_ISLEAF,
			setter = "setisLeaf"
			)
	
	public boolean getIsLeaf() {
		return isLeaf;
	}
	public void setIsLeaf(boolean newIsLeaf) {
		boolean oldisLeaf = isLeaf;
		isLeaf = newIsLeaf;
		firePropertyChange(ModelPackage.REDEFINABLEELEMENT_ISLEAF, oldisLeaf, newIsLeaf);
	}
	
	// getters for references
	
	public MetaTypedList getStateInvariant() {
		if(stateInvariant == null) {
			stateInvariant = new MetaTypedList(Constraint.class, this, ModelPackage.STATE_STATEINVARIANT);
		}
		return stateInvariant;
	}
	
	public MetaTypedList getDeferrableTrigger() {
		if(deferrableTrigger == null) {
			deferrableTrigger = new MetaTypedList(Trigger.class, this, ModelPackage.STATE_DEFERRABLETRIGGER);
		}
		return deferrableTrigger;
	}
	
	public MetaTypedList getEntry() {
		if(entry == null) {
//			entry = new MetaTypedList(Behavior.class, this, ModelPackage.STATE_ENTRY);
			entry = new MetaTypedList(Pseudostate.class, this, ModelPackage.STATE_ENTRY);
		}
		return entry;
	}
	
	public MetaTypedList getExit() {
		if(exit == null) {
//			exit = new MetaTypedList(Behavior.class, this, ModelPackage.STATE_EXIT);
			exit = new MetaTypedList(Pseudostate.class, this, ModelPackage.STATE_EXIT);
		}
		return exit;
	}
	
	public MetaTypedList getDoActvity() {
		if(doActvity == null) {
			doActvity = new MetaTypedList(Behavior.class, this, ModelPackage.STATE_DOACTVITY);
		}
		return doActvity;
	}
	
	public MetaTypedList getConnection() {
		if(connection == null) {
			connection = new MetaTypedList(ConnectionPointReference.class, this, ModelPackage.STATE_CONNECTION);
		}
		return connection;
	}
	
	public MetaTypedList getConnectionPoint() {
		if(connectionPoint == null) {
			connectionPoint = new MetaTypedList(Pseudostate.class, this, ModelPackage.STATE_CONNECTIONPOINT);
		}
		return connectionPoint;
	}
	
	public MetaTypedList getRegion() {
		if(region == null) {
			region = new MetaTypedList(Region.class, this, ModelPackage.STATE_REGION);
		}
		return region;
	}
	
	public MetaTypedList getSubmachine() {
		if(submachine == null) {
			submachine = new MetaTypedList(StateMachine.class, this, ModelPackage.STATE_SUBMACHINE);
		}
		return submachine;
	}
	
	public MetaTypedList getRedefinedState() {
		if(redefinedState == null) {
			redefinedState = new MetaTypedList(State.class, this, ModelPackage.STATE_REDEFINEDSTATE);
		}
		return redefinedState;
	}
	
	public MetaTypedList getOutgoing() {
		if(outgoing == null) {
			outgoing = new MetaTypedList(Transition.class, this, ModelPackage.VERTEX_OUTGOING);
		}
		return outgoing;
	}
	
	public MetaTypedList getIncoming() {
		if(incoming == null) {
			incoming = new MetaTypedList(Transition.class, this, ModelPackage.VERTEX_INCOMING);
		}
		return incoming;
	}
	
	public MetaTypedList getRedefinitionContext() {
		if(redefinitionContext == null) {
			redefinitionContext = new MetaTypedList(Classifier.class, this, ModelPackage.REDEFINABLEELEMENT_REDEFINITIONCONTEXT);
		}
		return redefinitionContext;
	}
	
	public MetaTypedList getRedefinedElement() {
		if(redefinedElement == null) {
			redefinedElement = new MetaTypedList(RedefinableElement.class, this, ModelPackage.REDEFINABLEELEMENT_REDEFINEDELEMENT);
		}
		return redefinedElement;
	}
	
	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.STATE_ISCOMPOSITE, isComposite);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.STATE_ISORTHOGONAL, isOrthogonal);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.STATE_ISSIMPLE, isSimple);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.STATE_ISSUBMACHINESTATE, isSubmachineState);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.REDEFINABLEELEMENT_ISLEAF, isLeaf);
		
		// references
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.STATE_STATEINVARIANT, stateInvariant);
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.STATE_DEFERRABLETRIGGER, deferrableTrigger);
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.STATE_ENTRY, entry);
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.STATE_EXIT, exit);
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.STATE_DOACTVITY, doActvity);
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.STATE_CONNECTION, connection);
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.STATE_CONNECTIONPOINT, connectionPoint);
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.STATE_REGION, region);
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.STATE_SUBMACHINE, submachine);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.STATE_REDEFINEDSTATE, redefinedState);		
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.VERTEX_OUTGOING, outgoing);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.VERTEX_INCOMING, incoming);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.REDEFINABLEELEMENT_REDEFINITIONCONTEXT, redefinitionContext);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.REDEFINABLEELEMENT_REDEFINEDELEMENT, redefinedElement);		
		
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes
		
		isComposite = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.STATE_ISCOMPOSITE);
		
		isOrthogonal = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.STATE_ISORTHOGONAL);
		
		isSimple = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.STATE_ISSIMPLE);
		
		isSubmachineState = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.STATE_ISSUBMACHINESTATE);
		
		isLeaf = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.REDEFINABLEELEMENT_ISLEAF);
		
		// references
		
		this.getStateInvariant().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.STATE_STATEINVARIANT));
		
		this.getDeferrableTrigger().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.STATE_DEFERRABLETRIGGER));
		
		this.getEntry().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.STATE_ENTRY));
		
		this.getExit().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.STATE_EXIT));
		
		this.getDoActvity().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.STATE_DOACTVITY));
		
		this.getConnection().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.STATE_CONNECTION));
		
		this.getConnectionPoint().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.STATE_CONNECTIONPOINT));
		
		this.getRegion().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.STATE_REGION));
		
		this.getSubmachine().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.STATE_SUBMACHINE, this));
		
		this.getRedefinedState().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.STATE_REDEFINEDSTATE, this));
		
		this.getOutgoing().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.VERTEX_OUTGOING));
		
		this.getIncoming().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.VERTEX_INCOMING, this));
		
		this.getRedefinitionContext().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.REDEFINABLEELEMENT_REDEFINITIONCONTEXT, this));
		
		this.getRedefinedElement().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.REDEFINABLEELEMENT_REDEFINEDELEMENT, this));
		
	}
	
	public void dynamicSet(String featureID, Object value) {
		if(featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes
		
		// references
		
		else if(ModelPackage.STATE_SUBMACHINE.equals(featureID)) {
			getSubmachine().add(value);
		}
		
		else if(ModelPackage.STATE_REDEFINEDSTATE.equals(featureID)) {
			getRedefinedState().add(value);
		}
		
		else if(ModelPackage.VERTEX_OUTGOING.equals(featureID)) {
			getOutgoing().add(value);
		}
		
		else if(ModelPackage.VERTEX_INCOMING.equals(featureID)) {
			getIncoming().add(value);
		}
		
		else if(ModelPackage.REDEFINABLEELEMENT_REDEFINITIONCONTEXT.equals(featureID)) {
			getRedefinitionContext().add(value);
		}
		
		else if(ModelPackage.REDEFINABLEELEMENT_REDEFINEDELEMENT.equals(featureID)) {
			getRedefinedElement().add(value);
		}
		
		else
			super.dynamicSet(featureID, value);
	}
}
 
 
 
 
 